<?php

// +----------------------------------------------------------------------
// | Apprh.Shop
// +----------------------------------------------------------------------
// | Copyright (c) 2017-2027 http://www.apprh.com All rights reserved.
// +----------------------------------------------------------------------
// | Notice: This code is not open source, it is strictly prohibited
// |         to distribute the copy, otherwise it will pursue its
// |         legal responsibility.
// +----------------------------------------------------------------------
// | Author: pp <124910168@qq.com>
// +----------------------------------------------------------------------

namespace app\home\controller\member;

use think\Db;
use service\DataService;

/**
 * Home后端-首页
 * Class Index
 * @package app\home\controller\member
 * @author pp <124910168@qq.com>
 * @date 2020/06/04 10:41
 */
class Index extends Admin
{
    public function _initialize()
    {
        parent::_initialize();
    }

    public function index()
    {
        return $this->fetch('');
    }

    public function info()
    {
        if ($this->request->isPost()) {
            $data = $this->request->post();
            // halt($data);
            $data['id'] = $this->uid;
            if (DataService::save("Member", $data, 'id')) {
                $this->success('信息修改成功！');
            }
            $this->error('信息修改失败！');
        }else{
            return $this->fetch('info');
        }
    }

    public function pass()
    {
        if ($this->request->isPost()) {
            $data = $this->request->post();
            // halt($data);
            if ($this->member['password'] != md5($data['oldpassword'])) {
                $this->error('原密码错误！');
            }
            if ($data['password'] == $data['oldpassword']) {
                $this->error('新密码与原密码相同！');
            }
            if ($data['password'] != $data['repassword']) {
                $this->error('两次输入的密码不一致！');
            }
            if (DataService::save("Member", ['id' => $this->uid, 'password' => md5($data['password'])], 'id')) {
                $this->success('密码修改成功，下次请使用新密码登录！');
            }
            $this->error('密码修改失败，请稍候再试！');
        }else{
            return $this->fetch('');
        }
    }
        
    public function vip(){
        $lMap = ['catid' => 7, 'status' => 1, 'id' => 48];
        $info = $this->article->where($lMap)->find();
        // halt($info);

        $data = [
            'info' => $info,
        ];
        return $this->fetch('', $data);
    }
}
